<html>

<head>
    <meta charset="utf-8" />
    <link href="http://at.alicdn.com/t/font_449040_f6dif9rq0itqpvi.css" type="text/css" rel="stylesheet"></link>
    <script src="js/jquery-3.2.1.min.js"></script>
    <link href="tui/tui-editor.min.css" type="text/css" rel="stylesheet"></link>
    <link href="tui/tui-editor-contents.min.css" type="text/css" rel="stylesheet"></link>
    <script src='tui/lib/markdown-it.min.js'></script>
    <script src="tui/lib/to-mark.min.js"></script>
    <script src="tui/lib/tui-code-snippet.min.js"></script>
    <script src="tui/lib/codemirror.js"></script>
    <script src="tui/lib/highlight.pack.js"></script>
    <script src="tui/lib/squire-raw.js"></script>
    <script src="tui/tui-editor-Editor-all.min.js"></script>
    <link rel="stylesheet" href="tui/lib/codemirror.css">
    <link rel="stylesheet" href="tui/lib/github.css">
    <style>
        html,
        body {
            margin: 0px;
            padding: 0px;
            font-size: 12px;
            font-family: Microsoft YaHei;
            overflow: hidden;
            height: 100%;
            width: 100%;
            user-select: none;
        }

        input {
            margin: 0px;
            padding: 0px;
            height: 24px;
            outline: none;
        }

        #articleFrame {
            border: none;
            position: absolute;
            top: 36px;
            bottom: 0px;
            left: 0px;
            right: 0px;
            display: none;
            height: 100%;
            width: 100%;
            z-index: 999999;
        }

        .pager {
            position: absolute;
            height: 72px;
            cursor: pointer;
            background: rgb(90, 160, 38);
            width: 32px;
            color: #fff;
            padding-top: 6px;
        }

        #articleListWrapper {
            left: 160px;
            right: 160px;
            overflow: hidden;
            display: none;
            border-radius: 6px;
            position: absolute;
            top: 50%;
            height: 530px;
            margin-top: -265px;
        }

        #closePager {
            border-top-right-radius: 6px;
            border-bottom-right-radius: 6px;
            right: 0px;
            top: 0px;
            height: 32px;
            padding: 0px;
            line-height: 32px;
            background: rgb(221, 72, 20);
        }

        #rightPager {
            border-top-right-radius: 6px;
            border-bottom-right-radius: 6px;
            right: 0px;
            bottom: 0px;
        }

        #leftPager {
            border-top-left-radius: 6px;
            border-bottom-left-radius: 6px;
            bottom: 0px;
        }

        #newArticlePager {
            top: 0px;
            border-top-left-radius: 6px;
            border-bottom-left-radius: 6px;
        }

        #articleListContainer {
            background: #ffffff;
            margin-left: 32px;
            margin-right: 32px;
            overflow: hidden;
        }

        #articleListBg,
        #codeBg,
        #htmlBg {
            background: rgba(0, 0, 0, 0.6);
            position: absolute;
            top: 36px;
            left: 0px;
            right: 0px;
            bottom: 0px;
            z-index: 99999;
            text-align: center;
            display: none;
        }

        .toolBtn {
            width: 36px;
            float: right;
            cursor: pointer;
            -webkit-app-region: no-drag;
        }

        #winClose:hover {
            background: rgb(221, 72, 20);
        }

        .toolBtn:hover {
            background: rgb(60, 60, 60);
        }



        .wrap {
            height: 30px;
            line-height: 30px;
            border-bottom: 1px solid #aaaaaa;
            border-top: 1px solid #aaaaaa;
        }

        .iconfont {
            font-size: 13px;
        }

        .txt {
            font-size: 13px;
            font-weight: 500;
        }

        .editorBtnSelected {
            background: rgb(215, 212, 240);
        }

        .editorBtn {
            height: 30px;
            line-height: 30px;
            text-align: center;
            float: left;
            width: 37px;
            cursor: pointer;
            color: #555555;
            border-right: 1px solid #aaaaaa;
        }

        .editorBtn:hover {
            background: #FFFFFF;
        }

        ::-webkit-scrollbar {
            width: 6px;
            height: 6px;
            background-color: #fff;
        }

        ::-webkit-scrollbar-track {
            border-radius: 6px;
            background-color: #fff;
        }

        ::-webkit-scrollbar-thumb {
            border-radius: 2px;
            background-color: #ddd;
        }

        .titleRow {
            line-height: 32px;
            height: 32px;
            border-bottom: dotted 1px #aaaaaa;
            overflow: hidden;
            text-align: left;
            font-size: 14px;
            cursor: pointer;
        }

        #okHtmlBtn,
        #saveCodeBtn {
            width: 98px;
            background-color: rgb(90, 160, 38);
            cursor: pointer;
            display: inline-block;
            border-radius: 3px;
        }

        #htmlCancelBtn,
        #cancelCodeBtn {
            background: rgb(221, 72, 20);
            color: #fff;
            display: inline-block;
            cursor: pointer;
            width: 98px;
            border-radius: 3px;
        }

        #htmlTa,
        #codeTa {
            width: 100%;
            height: 100%;
            padding: 6px;
            resize: none;
        }
    </style>
</head>

<body style="background:  #eeeeee;">
    <div style="height: 36px;background: rgb(74, 76, 88);color: #FFFFFF;
        -webkit-app-region: drag;
        line-height: 36px;font-size: 16px;">
        <div style="float: left;margin-left: 12px;font-size: 18px;">
            无忧博客园
            <span style="color: #aaaaaa;font-size: 12px;">博客园文章编辑器-by liulun</span>
        </div>
        <div style="float: right;width: 160px;text-align: center;">
            <div id="winClose" class="toolBtn">
                <i class="iconfont icon-close47"></i>
            </div>
            <div id="winMax" class="toolBtn">
                <i class="iconfont icon-max"></i>
            </div>
            <div id="winMin" class="toolBtn">
                <i class="iconfont icon-min"></i>
            </div>
            <div id="toolRefreshBtn" class="toolBtn">
                <i class="iconfont icon-refresh"></i>
            </div>
        </div>
    </div>
    <div style="height: 46px;clear: both;background:  #eeeeee;">
        <div id="saveBtn" style="float: right;line-height: 32px;height: 32px;
            background: rgb(221, 72, 20);color: #ffffff;
            border-top-left-radius: 12px;margin-top: 6px;
            border-bottom-left-radius: 12px;
            box-shadow: -3px 0px 3px #888888;
            cursor: pointer;
            width: 80px;text-align: center;">
            保存文章
        </div>
        <div id="getListBtn" style="float: left;line-height: 32px;height: 32px;width: 80px;text-align: center;
            background: rgb(90, 160, 38);color: #ffffff;
            border-top-right-radius: 12px;margin-top: 6px;
            border-bottom-right-radius: 12px;
            box-shadow: 3px 0px 3px #888888;
            cursor: pointer;
            ">
            文章列表
        </div>
        <div style="margin-left: 90px;margin-right: 90px">
            <input id="titleInput" type="text" placeholder="请在这里填写文章标题..." style="border: none;height: 46px;line-height: 46px;text-align: center;
                font-weight:bold; font-size: 16px;text-indent: 8px;width: 100%;background:  #eeeeee;" />
        </div>
    </div>
    <div id="editSection" style="background: #ffffff;">

    </div>
    <div id="articleListBg">
        <div style="font-size: 58px;text-align: center;margin-top: 198px;color: #ffffff;font-weight: bold;">
            请稍后...
        </div>
        <div id="articleListWrapper">
            <div id="articleListContainer">
                <div style="float: left;width: 50%;margin-left: -1px;border-right: dotted 1px #aaaaaa;height: 100%;">
                    <div id="articleLeft" style="margin: 16px;"></div>
                </div>
                <div style="margin-left: 50%;height: 100%;">
                    <div id="articleRight" style="margin: 16px;"></div>
                </div>
            </div>
            <div class="pager" id="rightPager">
                <div style="width: 16px;margin-left: 8px;">向下翻页</div>
            </div>
            <div class="pager" id="leftPager">
                <div style="width: 16px;margin-left: 8px;">向上翻页</div>
            </div>
            <div class="pager" id="closePager">
                <i class="iconfont icon-close47"></i>
            </div>
            <div class="pager" id="newArticlePager">
                <div style="width: 16px;margin-left: 8px;">新增文章</div>
            </div>
        </div>
    </div>
    <div id="codeBg">
        <div id="codeContainer" style="margin-top: 86px;margin-left: auto;margin-right: auto;
        border-radius: 6px;overflow: hidden;
        width: 698px;background: #fff;height: 500px;">
            <textarea id="codeTa"></textarea>
        </div>
        <div style="margin: 0 auto;color: #fff;line-height: 32px;height: 32px;margin-top: 6px;">
            <div id="cancelCodeBtn">
                取消
            </div>
            <div id="saveCodeBtn">
                保存
            </div>
        </div>
    </div>
    <div id="htmlBg">
        <div style="margin-top: 36px;margin-left: auto;margin-right: auto;
        border-radius: 6px;overflow: hidden;
        width: 698px;background: #fff;height: 600px;">
            <textarea id="htmlTa"></textarea>
        </div>
        <div style="margin: 0 auto;color: #fff;line-height: 32px;height: 32px;margin-top: 6px;">
            <div id="htmlCancelBtn">
                取消
            </div>
            <div id="okHtmlBtn">
                修正
            </div>
        </div>
    </div>
    <script src="js/bridge.js"></script>
    <script>
        var win = nw.Window.get();
        var isMaxSize = false;
        document.body.onselectstart = document.body.oncontextmenu = function () { return false; }
        //标题栏的三个按钮;
        $(function () {
            $("#winMin").click(function () {
                win.minimize();
            })
            $("#winMax").click(function () {
                if (isMaxSize) {
                    win.restore();
                    isMaxSize = false;
                    $(this).find("i").removeClass("icon-tubiaozhizuomoban").addClass("icon-max");                    

                } else {
                    win.maximize();
                    isMaxSize = true;
                    $(this).find("i").removeClass("icon-max").addClass("icon-tubiaozhizuomoban");
                    setTimeout(function(){
                        var h = win.height - 96;
                        window.tuiEditorInstance.height(h+"px");
                    },300);
                }
            })
            $("#winClose").click(function () {
                win.close();
            })
            $("#toolRefreshBtn").click(function () {
                window.location.href = window.location.href;
            })
        })
        $(function () {
            $("#getListBtn").click(function () {
                bky.getList(bky.pageIndex);
            });
            $("#rightPager").click(function () {
                bky.getList(bky.pageIndex + 1);
            })
            $("#leftPager").click(function () {
                if (bky.pageIndex - 1 < 1) {
                    return;
                }
                bky.getList(bky.pageIndex - 1);
            })
            $("#closePager").click(function () {
                $("#articleListBg").hide();
            })
            $("#saveBtn").click(function () {
                var obj = {};
                obj.title = $("#titleInput").val();
                obj.content = editorFrame.body.innerHTML;
                obj.content = '<div class="markdown-body">' + obj.content + "</div>";
                if (obj.title.length < 2 || obj.content.length < 6) {
                    alert("文章标题或者文章正文字数太少");
                    return;
                }
                bky.saveArticle(obj);
            });
            $("#newArticlePager").click(bky.newArticle);
            window.tuiEditorInstance = $('#editSection').tuiEditor({
                initialEditType: 'markdown',
                previewStyle: 'vertical',
                height: '300px'
            });
            var resizeFunc = function(){
                var h = win.height - 85;
                window.tuiEditorInstance.height(h+"px");
            };
            window.onresize = resizeFunc;
            resizeFunc();
            setTimeout(function(){
                window.tuiEditor.insertText("## 这是我的内容");
            },1000)
            
        })
    </script>
</body>

</html>